
* Formatting
graph set window fontface "Times New Roman"	// use Times New Roman as the default font for Graph window
// 	 graph set window fontface default 			// use this to restore to factury setting if preferred later

set scheme s1mono

*******************************************************************************
*************** Figure A2: plotting treatment effects by gender ***************

* Females:
use "${ddata}cleaned_data_wACSweight.dta", clear 

keep if male==0

forvalues i=0(1)5 {

	reg qs2_`i' treatment [aweight=weight_ACS], robust

	matrix q`i' = r(table)

	gen p_`i'= q`i'[4,1]

}

keep userid qs2_* p_* treatment sce  weight_ACS

reshape long qs2_ p_,  i( userid sce treatment weight_ACS) j(questions)

rename qs2_ answers
rename p_ p_value

collapse (mean) mean= answers p_value (sd) sd=answers (count) n=answers [aweight=weight_ACS], by(question treatment)

generate hiwrite = mean + invttail(n-1,0.025)*(sd / sqrt(n))
generate lowrite = mean - invttail(n-1,0.025)*(sd / sqrt(n))

generate q_t = 1    if question==0&treatment==0
replace  q_t = 2    if question==0&treatment==1
replace  q_t = 4    if question==1&treatment==0
replace  q_t = 5    if question==1&treatment==1
replace  q_t = 7    if question==2&treatment==0
replace  q_t = 8    if question==2&treatment==1
replace  q_t = 10   if question==3&treatment==0
replace  q_t = 11   if question==3&treatment==1
replace  q_t = 13   if question==4&treatment==0
replace  q_t = 14   if question==4&treatment==1
replace  q_t = 16   if question==5&treatment==0
replace  q_t = 17   if question==5&treatment==1

sort q_t

gen 	position=1.5  if question==0
replace position=4.5  if question==1
replace position=7.5  if question==2
replace position=10.5 if question==3
replace position=13.5 if question==4
replace position=16.5 if question==5


gen _plotp = ""

forvalues i=0(1)5 {

	egen  	max_`i' = max(mean) 	if question==`i'
	gen   	ppv_`i' = p_value 		if question==`i'
	egen  	pv_`i'  = max(ppv_`i')

	local p`i': display %4.3f pv_`i' 			 	 //store p-value with correct formating in local macro
	replace  _plotp = "p=`p`i''" 	if question==`i' //store p-value with brackets as string variable

}



gen y=.

forvalues i=0(1)5 {

	replace y = max_`i'+7 if question==`i'

}


gen    yy = mean+2
gen label = strofreal(mean,"%03.1f")

twoway (bar mean q_t if treatment==0,  color(navy%30) ) ///
	(bar mean q_t if treatment==1, color(navy%90) ) ///
	(scatter  y position, msym(none) mlab(_plotp) mlabp(12) mlabc(black) mlabs(vsmall)) ///
	(scatter  yy q_t, msym(none) mlab(label) mlabp(12) mlabc(black) mlabs(vsmall)) ///
	(rcap hiwrite lowrite q_t, lcolor(gray)),  ///
	legend( order(1 "Control" 2 "Treatment" ) ) ///
	xlabel( 1.5 "Mother reject offer" 4.5 "15% less" 7.5 "Same" 10.5 "15% more" 13.5 "30% more" 16.5 "50% more", noticks  labsize(small)) ///
	ylabel(0(10)80,labsize(small)) yscale(r(0 70)) ///
	xtitle("   Mother makes", size(small)) legend(region(lstyle(none)) size(vsmall)) ytitle("Prob. recommends conservative action", size(small)) title("A. Women", size(small))

graph save "${o}main_female", replace



* Males:
use "${ddata}cleaned_data_wACSweight.dta", clear  

keep if male==1

forvalues i=0(1)5 {

	reg qs2_`i' treatment [aweight=weight_ACS], robust

	matrix q`i' = r(table)

	gen p_`i'= q`i'[4,1]

}

keep userid qs2_* p_* treatment sce weight_ACS

reshape long qs2_ p_,  i( userid sce treatment weight_ACS) j(questions)

rename qs2_ answers
rename p_ p_value

collapse (mean) mean= answers p_value (sd) sd=answers (count) n=answers  [aweight=weight_ACS], by(question treatment)


generate hiwrite = mean + invttail(n-1,0.025)*(sd / sqrt(n))
generate lowrite = mean - invttail(n-1,0.025)*(sd / sqrt(n))

generate q_t = 1    if question==0&treatment==0
replace  q_t = 2    if question==0&treatment==1
replace  q_t = 4    if question==1&treatment==0
replace  q_t = 5    if question==1&treatment==1
replace  q_t = 7    if question==2&treatment==0
replace  q_t = 8    if question==2&treatment==1
replace  q_t = 10   if question==3&treatment==0
replace  q_t = 11   if question==3&treatment==1
replace  q_t = 13   if question==4&treatment==0
replace  q_t = 14   if question==4&treatment==1
replace  q_t = 16   if question==5&treatment==0
replace  q_t = 17   if question==5&treatment==1

sort q_t

gen 	position=1.5  if question==0
replace position=4.5  if question==1
replace position=7.5  if question==2
replace position=10.5 if question==3
replace position=13.5 if question==4
replace position=16.5 if question==5

gen _plotp = ""

forvalues i=0(1)5 {

	egen 	max_`i' = max(mean) 	if question==`i'
	gen 	ppv_`i' = p_value 		if question==`i'
	egen 	pv_`i'  = max(ppv_`i')

	local p`i': display %4.3f pv_`i' 			 	  //store p-value with correct formating in local macro
	replace _plotp  = "p=`p`i''" 	if question==`i' //store p-value with brackets as string variable
}

gen y=.

forvalues i=0(1)5 {
	replace y=max_`i'+7 if question==`i'
}


gen yy	  = mean+2
gen label = strofreal(mean,"%03.1f")

twoway  (bar mean q_t if treatment==0, color(navy%30) ) ///
	(bar mean q_t if treatment==1, color(navy%90) ) ///
	(scatter  y position, msym(none) mlab(_plotp) mlabp(12) mlabc(black) mlabs(vsmall)) ///
	(scatter  yy q_t, msym(none) mlab(label) mlabp(12) mlabc(black) mlabs(vsmall)) ///
	(rcap hiwrite lowrite q_t, lcolor(gray)), ///
	legend( order(1 "Control" 2 "Treatment" ) ) ///
	xlabel( 1.5 "Mother reject offer" 4.5 "15% less" 7.5 "Same" 10.5 "15% more" 13.5 "30% more" 16.5 "50% more", noticks  labsize(small)) ///
	ylabel(,labsize(small)) ///
	xtitle("   Mother makes", size(small)) legend(region(lstyle(none)) size(small)) ytitle("Prob. recommends conservative action", size(small)) title("B. Men", size(small))
graph save "${o}/main_male", replace


* Combine:
grc1leg "${o}main_female.gph" "${o}main_male.gph", legendfrom("${o}main_female.gph") col(1)
graph export "${o}main_gender.pdf", replace

erase "${o}main_female.gph" 
erase "${o}main_male.gph"
